<%@page import="com.bean.MessageBean"%>
<%@page import="com.bean.RecordBean"%>
<%@page import="com.bean.InstrumentBean"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
	@SuppressWarnings("unchecked")
	ArrayList<RecordBean> list = (ArrayList<RecordBean>)request.getAttribute("state");
	MessageBean message = (MessageBean)request.getAttribute("message");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'statistic.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type = "text/css" href="CSS/history.css">
	<script type="text/javascript">
	function check(form)
	{
	var key = form.key.value;
	var value = form.value.value;
	if (key == "barcode") {
		if (value == "")
			return false;
		if (value.length > 45) {
			alert('barcode is illegal,maxlength is 45');
			return false;
		}
		if (!/^\d+$/.test(value)) {
			alert('barcode is illegal,number is ok');
			return false;
		}
	}
	if (key == "insname") {
		if (value == "")
			return false;
	}
	if (key == "userid") {
		if (value == "")
			return false;
		if (!/^\d+$/.test(value)) {
			alert('userID is illegal');
			return false;
		}
		if (value.length != 8) {
			alert('userID length is illegal,8 bits');
			return false;
		}
	}
	form.submit();
	}
	</script>
</head>

<body >

<div class="title2" style="width: 95%">
	<h1>State Query</h1>
<form action="StateQueryServlet" method="post" name ="form1" style="border: 0px;margin: 0;padding: 2">
	<table align="center" height="29">
	<tr>
	  <td align="center">
	  <%
	  	 String key = "barcode";
	  	 String value = "";
	  	 if(null != message)
	  	 {
	  		 key = message.getKey();
	  		 value = message.getValue();
	  	 }
	  %>
		<select name="key">
           <option value="barcode" <%if("barcode".equals(key)){%> selected<%} %>>Barcode</option>
           <option value="insname" <%if("insname".equals(key)){%> selected<%} %>>Tool Name</option>
           <option value="userid" <%if("userid".equals(key)){%> selected<%} %>>User ID</option>
        </select>
        <input name="value" value="<%=value %>" type="text"  size="37" maxlength="100">
	 	<input type = "button" value = "submit" onclick="return check(form1);">
       	 </td>
	 
	</tr></table>
</form>
</div>
<%
if(null != list)
{
if(list.size()==0)
{%> <font size="3px" color="red">normal</font> <%}else{%>  <%}}%>

<table width="95%" id="mytab"  border="1" class="t2">
<%if("userid".equals(key)) {%>
  <thead>
  <tr>
    <th width="4%">num</th>
    <th width="10%">UserID</th>
    <th width="10%">FirstName</th>
    <th width="10%">LastName</th>
    <th width="15%">E-mail</th>
    <th width="15%">Tool Name</th>
    <th width="10%">Bar-code</th>
    <th width="6%">In Lab</th>
    <th width="10%">BorrowDate</th>
    <th width="10%">BackDate</th>
   </tr>
  </thead>
<%}else{ %>
	<thead>
    <tr>
    <th width="4%">num</th>
    <th width="15%">Tool Name</th>
    <th width="10%">Bar-code</th>
    <th width="6%">In Lab</th>
    <th width="10%">UserID</th>
    <th width="10%">FirstName</th>
    <th width="10%">LastName</th>
    <th width="15%">E-mail</th>
    <th width="10%">BorrowDate</th>
    <th width="10%">Should Back Date</th>
   </tr>
  </thead>
<%} %>
 <tbody style="overflow: scroll; height: 5px">
<%
    String insName = "";
	String barcode = "";
	String ifin = "";
	String userID = "";
	String FirstName = "";
	String LastName = "";
	String email = "";
	String status = "";
	String BorrowDate = "";
	String sBackDate = "";
	int num = 0;
	if(null != list && list.size()!=0)
	{
		Iterator<RecordBean> iter = list.iterator();
		while(iter.hasNext())
		{
			RecordBean his = iter.next();
			insName = his.getInsName();
			barcode = his.getBarcode();
			ifin = his.getIfIn();
			userID = his.getUserID();
			FirstName = his.getFirstname();
			LastName = his.getLastname();
			email = his.getEmail();
			BorrowDate = his.getBorrowDate().toString();
			sBackDate = his.getSBackDate().toString();
			num++;
			if("userid".equals(key))
			{
%>
  			<tr <%if(num%2!=0){ %>class="a1"<%} %>>
  			<td><%=num %></td>
   			<td><%=userID%></td>
   			<td><%=FirstName %></td>
   			<td><%=LastName%></td>
   			<td><%=email%></td>
   			<td><%=barcode %></td>
  			<td><%=insName %></td>
  			<td><%=ifin %></td>
   			<td><%=BorrowDate %></td>
   			<td><%=sBackDate%></td>
  			</tr>
<%	 		}else{%>
			<tr<%if(num%2!=0){ %>class="a1"<%} %>>
			<td><%=num %></td>
			<td><%=barcode %></td>
			<td><%=insName %></td>
			<td><%=ifin %></td>
			<td><%=userID%></td>
			<td><%=FirstName %></td>
			<td><%=LastName%></td>
			<td><%=email%></td>
			<td><%=BorrowDate %></td>
			<td><%=sBackDate%></td>
			</tr>
			<%} %>	
<%
		}
	}else{
%>
	
			<tr>
			<td><%=num %></td>
			<td><%=insName %></td>
			<td><%=barcode %></td>
			<td><%=ifin %></td>
			<td><%=userID%></td>
			<td><%=FirstName %></td>
			<td><%=LastName%></td>
			<td><%=email%></td>
			<td><%=BorrowDate %></td>
			<td><%=sBackDate%></td>
			</tr>

 <%} %>	
 </tbody>
</table>

</body>
</html>
